package com.example.superoa.controller;

import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.superoa.model.pojos.Rbiographical;
import com.example.superoa.model.pojos.Rinterview;
import com.example.superoa.model.pojos.Rinterviewer;
import com.example.superoa.model.service.RinterviewService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Controller
public class RinterviewController {
		@Autowired
		private RinterviewService intservice;	
				
		//查询所有面试
		@PostMapping("select-interview")
		@ResponseBody
		public Map<String,Object> show(int page,int rows) {
			Map<String,Object> map = new HashMap<>();
			//先分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray j = intservice.findAllview();
			int i=1;
			for (Object object : j) {
				JSONObject obj=(JSONObject)object;
				obj.put("viewid", i);
				i++;
			}
			//总记录
			map.put("total", pg.getTotal());
			//页内容
			map.put("rows", j);
			return map;
		}		
		//根据id查询		
		@RequestMapping("interview")
		@ResponseBody
		public JSONArray interview() {
			return intservice.findAllview();
		}	
		//初始化
		@RequestMapping("interview-allplan")
		@ResponseBody
		public JSONArray selectallinterview(Integer riviewid) {
			JSONArray json = intservice.finByIdview(riviewid);			
				return json;
		}
		/**修改面试记录，添加面试结果
		 * @return
		 */
		@RequestMapping("viewinsert")
		@ResponseBody
		public void interviewinsert(Integer riviewid,String riviewoption,String riviewcontent) {
			intservice.xiugaiinterview(riviewid,riviewoption,riviewcontent);
		}
		/**新增面试
		 * @return
		 */
		@RequestMapping("select-jianliinsert")
		@ResponseBody
		public String jianliinsert(Rinterview interview,Rinterviewer interviewer,Integer staff_id,Rbiographical rbiographical,Integer position_id,Integer rapplyid) {
			intservice.jianliinsert(interview,interviewer,staff_id,rbiographical,position_id,rapplyid);
			return "redirect:main-administrator:recruitinterview";				
		}
		//审批录用		结果
		@RequestMapping("luyong")
		@ResponseBody
		public int luyong(Integer id,Integer rid,Integer rrid,Integer jie) {
			intservice.luyong(id,rid,rrid,jie);
			return 1;
		}
		//查找面试人
		@RequestMapping("select_interviewer")
		@ResponseBody
		public JSONArray select_interviewer() {
			JSONArray json = intservice.selectRinterviewer();
			int i=1;
			for (Object object : json) {
				JSONObject obj=(JSONObject)object;
				obj.put("sortable", i);
				i++;
			}
			return json;
		}
		//根据应聘职位查询面试官
		@RequestMapping("select-positions")
		@ResponseBody
		public JSONArray selectpositions(Integer id) {
			JSONArray json = intservice.selectpositions(id);
			int i=1;
			for (Object object : json) {
				JSONObject obj=(JSONObject)object;
				obj.put("sortable", i);
				i++;
			}
			return json;	
		}
}